WOLF core
WOLF: A Modular Estimation Framework for Robotics
XXXXXXXXXXXXXXXXXXXXXXXXvoid(0)" frameborder="0" name="MSearchResults" id="MSearchResults">
wolf::FactorAutodiff< FacT, RES, BLOCK_SIZES > Class Template Reference

Base class of factors with automatic differentiation: the Jacobians are computed with jets. More...

#include <core/factor/factor_autodiff.h>

Inheritance diagram for wolf::FactorAutodiff< FacT, RES, BLOCK_SIZES >:
[legend]

Public Types

typedef autodiff::Jet< double, jet_size > WolfJet
 Jet type, with the derivatives wrt all the state block components. More...
 

Public Member Functions

 FactorAutodiff (const std::string &_type, const FactorTopology &_top, const Eigen::VectorXd &_measurement, const Eigen::MatrixXd &_measurement_sqrt_information_upper, const NodeStateBlocksPtrList &_node_state_block_list, const ProcessorBasePtr &_processor_ptr, const std::vector< StateBlockPtr > &_state_ptrs, bool _apply_loss_function, FactorStatus _status=FAC_ACTIVE)
 Constructor (see FactorBase). It checks the state block sizes and initializes the jets. More...
 
 ~FactorAutodiff () override=default
 
bool evaluate (const std::vector< const double * > &_states_ptr, Eigen::VectorXd &_residual, std::vector< Eigen::MatrixXd > &_jacobians) const override
 Evaluates the residual and, if _jacobians is not empty, the Jacobians (see FactorBase::evaluate()) More...
 
Eigen::VectorXd expectation (const std::vector< const double * > &_states_ptr) const override
 Evaluates the expected measurement at the state values in _states_ptr. More...
 
unsigned int getSize () const override
 Returns the residual size. More...
 
virtual Eigen::VectorXd expectation (const std::vector< const double * > &_states_ptr) const=0
 Evaluates the expected measurement at the state values in _states_ptr. More...
 
Eigen::VectorXd expectation () const
 Evaluates the expected measurement at the current state values. More...
 
- Public Member Functions inherited from wolf::FactorBase
 FactorBase (const std::string &_type, const FactorTopology &_top, const JacobianMethod &_jac_method, const Eigen::VectorXd &_measurement, const Eigen::MatrixXd &_measurement_sqrt_information_upper, const NodeStateBlocksPtrList &_node_state_block_list, const ProcessorBasePtr &_processor_ptr, const std::vector< StateBlockPtr > &_state_ptrs, bool _apply_loss_function, FactorStatus _status=FAC_ACTIVE)
 Constructor from the measurement, the upper triangular square root of its information matrix (Cholesky), the constrained nodes and their state blocks. More...
 
 ~FactorBase () override=default
 
virtual void remove (bool viral_remove_parent_without_children=false)
 Removes the factor (notifying the problem) and unregisters it from the factored nodes. More...
 
bool hasChildren () const override
 Returns whether the node has children in the Wolf tree. More...
 
unsigned int id () const
 Returns the factor id. More...
 
virtual FactorTopology getTopology () const final
 Returns the topology of the factor. More...
 
virtual void getTopology (FactorTopology _top) final
 Sets the topology of the factor (note: this setter is named getTopology) More...
 
std::string getTopologyString () const
 Returns the topology of the factor as a string. More...
 
virtual bool evaluate (const std::vector< const double * > &_states_ptr, Eigen::VectorXd &_residual, std::vector< Eigen::MatrixXd > &_jacobians) const =0
 Evaluates the residual (weighted by the measurement noise) and, optionally, the Jacobians at the state values in _states_ptr. More...
 
virtual Eigen::VectorXd residual () const
 Evaluates the residual (weighted by the measurement noise) at the current state values. More...
 
virtual Eigen::VectorXd expectation (const std::vector< const double * > &_states_ptr) const =0
 Evaluates the expected measurement at the state values in _states_ptr. More...
 
Eigen::VectorXd expectation () const
 Evaluates the expected measurement at the current state values. More...
 
virtual double cost () const
 Evaluates the cost of the factor at the current state values: squared norm of the residual (without loss function) More...
 
virtual JacobianMethod getJacobianMethod () const final
 Returns the jacobians computation method. More...
 
virtual std::vector< StateBlockConstPtr > getStateBlockPtrVector () const
 Returns a vector of pointers to the states in which this factor depends. More...
 
virtual std::vector< StateBlockPtr > getStateBlockPtrVector ()
 Returns a vector of pointers to the states in which this factor depends. More...
 
virtual std::vector< unsigned int > getStateSizes () const
 Returns a vector of the states sizes. More...
 
virtual const Eigen::VectorXd & getMeasurement () const
 Returns a reference to the measurement. More...
 
virtual const Eigen::MatrixXd & getMeasurementSquareRootInformationUpper () const
 Returns a reference to the measurement square root information. More...
 
FeatureBaseConstPtr getFeature () const
 Returns a pointer to the feature constrained from. More...
 
FeatureBasePtr getFeature ()
 Returns a pointer to the feature constrained from. More...
 
CaptureBaseConstPtr getCapture () const
 Returns a pointer to its capture. More...
 
CaptureBasePtr getCapture ()
 Returns a pointer to its capture. More...
 
FrameBaseConstPtr getFrame () const
 Returns a pointer to its frame. More...
 
FrameBasePtr getFrame ()
 Returns a pointer to its frame. More...
 
ProcessorBaseConstPtr getProcessor () const
 Returns the processor that created the factor (nullptr if none) More...
 
ProcessorBasePtr getProcessor ()
 Returns the processor that created the factor (nullptr if none) More...
 
virtual unsigned int getSize () const =0
 Returns the factor residual size. More...
 
FactorStatus getStatus () const
 Returns the status (active or inactive) More...
 
void setStatus (FactorStatus _status)
 Sets the status, notifying the problem to add (active) or remove (inactive) the factor from the solver. More...
 
bool getApplyLossFunction () const
 Returns whether a loss function is applied to this factor. More...
 
NodeStateBlocksWPtrList getNodesFactored ()
 Returns the nodes whose state blocks are constrained by the factor. More...
 
FrameBaseWPtrList getFramesFactored ()
 Returns the frames whose state blocks are constrained by the factor. More...
 
CaptureBaseWPtrList getCapturesFactored ()
 Returns the captures whose state blocks are constrained by the factor. More...
 
LandmarkBaseWPtrList getLandmarksFactored ()
 Returns the landmarks whose state blocks are constrained by the factor. More...
 
SensorBaseWPtrList getSensorsFactored ()
 Returns the sensors whose state blocks are constrained by the factor. More...
 
NodeStateBlocksConstWPtrList getNodesFactored () const
 Returns the nodes whose state blocks are constrained by the factor. More...
 
FrameBaseConstWPtrList getFramesFactored () const
 Returns the frames whose state blocks are constrained by the factor. More...
 
CaptureBaseConstWPtrList getCapturesFactored () const
 Returns the captures whose state blocks are constrained by the factor. More...
 
LandmarkBaseConstWPtrList getLandmarksFactored () const
 Returns the landmarks whose state blocks are constrained by the factor. More...
 
SensorBaseConstWPtrList getSensorsFactored () const
 Returns the sensors whose state blocks are constrained by the factor. More...
 
bool hasNode (const NodeStateBlocksConstPtr &_nsb) const
 Returns whether the factor constrains state blocks of the node. More...
 
bool hasFrame (const FrameBaseConstPtr &_frm) const
 Returns whether the factor constrains state blocks of the frame. More...
 
bool hasCapture (const CaptureBaseConstPtr &_cap) const
 Returns whether the factor constrains state blocks of the capture. More...
 
bool hasLandmark (const LandmarkBaseConstPtr &_lmk) const
 Returns whether the factor constrains state blocks of the landmark. More...
 
bool hasSensor (const SensorBaseConstPtr &_sen) const
 Returns whether the factor constrains state blocks of the sensor. More...
 
void link (FeatureBasePtr ftr)
 Links the factor to a feature and registers it in the factored nodes. More...
 
virtual void printHeader (int _depth, bool _factored_by, bool _metric, bool _state_blocks, std::ostream &_stream, std::string _tabs="") const
 Prints the information of this node (not of its children) More...
 
void print (int _depth, bool _factored_by, bool _metric, bool _state_blocks, std::ostream &_stream=std::cout, std::string _tabs="") const
 Prints this node and, depending on the depth, its children. More...
 
virtual CheckLog localCheck (bool _verbose, std::ostream &_stream, std::string _tabs="") const
 Checks the consistency of this node (not of its children) More...
 
bool check (CheckLog &_log, bool _verbose, std::ostream &_stream, std::string _tabs="") const
 Checks the consistency of this node and its children, composing the log. More...
 
- Public Member Functions inherited from wolf::NodeBase
 NodeBase (const std::string &_category, const std::string &_type="Undefined", const std::string &_name="")
 Constructor. More...
 
virtual ~NodeBase ()=default
 Destructor. More...
 
unsigned int nodeId () const
 Returns the node id, unique over the whole Wolf tree. More...
 
std::string getCategory () const
 Returns the category of the node. More...
 
std::string getType () const
 Returns the type (subcategory) of the node. More...
 
std::string getName () const
 Returns the name of the node. More...
 
bool isRemoving () const
 Returns whether the node is being removed. More...
 
virtual bool hasChildren () const =0
 Returns whether the node has children in the Wolf tree. More...
 
void setType (const std::string &_type)
 Sets the type (subcategory) of the node. More...
 
void setName (const std::string &_name)
 Sets the name of the node. More...
 
ProblemConstPtr getProblem () const
 Returns the problem the node belongs to. More...
 
ProblemPtr getProblem ()
 Returns the problem the node belongs to. More...
 

Static Public Attributes

static constexpr unsigned int n_blocks = sizeof...(BLOCK_SIZES)
 Number of state blocks. More...
 
static constexpr unsigned int jet_size = (BLOCK_SIZES + ...)
 Size of the derivatives part of the jets. More...
 

Protected Attributes

std::array< WolfJet, jet_size > state_jets_
 Jets of all state blocks (stacked) More...
 
std::vector< const WolfJet * > state_jets_ptr_
 Pointers to the jets of each state block. More...
 
Eigen::Matrix< WolfJet, RES, 1 > residual_jets_
 Jets of the residual. More...
 
- Protected Attributes inherited from wolf::FactorBase
unsigned int factor_id_
 Factor id, unique among factors. More...
 
FactorTopology topology_
 Topology of factor. More...
 
JacobianMethod jacobian_method_
 Jacobian method. More...
 
FactorStatus status_
 Status of factor. More...
 
bool apply_loss_function_
 Whether a loss function is applied to this factor. More...
 
Eigen::VectorXd measurement_
 Measurement vector. More...
 
Eigen::MatrixXd measurement_sqrt_information_upper_
 Upper square root of the information matrix. More...
 
std::vector< unsigned int > state_block_sizes_
 Vector containing sizes of the state blocks involved. More...
 
std::vector< StateBlockPtr > state_block_vector_
 Vector containing the state blocks involved. More...
 
- Protected Attributes inherited from wolf::NodeBase
ProblemWPtr problem_ptr_
 Problem the node belongs to. More...
 
unsigned int node_id_
 Node id. It is unique over the whole Wolf Tree. More...
 
std::string node_category_
 Text label identifying the category of node ("SENSOR", "FEATURE", etc) More...
 
std::string node_type_
 Type or subcategory of node (derived class name: "SensorOdom2d", etc) More...
 
std::string node_name_
 
bool is_removing_
 A flag for safely removing nodes from the Wolf tree. See remove(). More...
 

Static Protected Attributes

static constexpr std::array< unsigned int, n_blocks > block_sizes_ {BLOCK_SIZES...}
 Size of each state block. More...
 
static constexpr std::array< unsigned int, n_blocks > jacobian_locations_
 Position of each state block in the jets. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from wolf::FactorBase
template<typename classType , typename... T>
static std::shared_ptr< classType > emplace (FeatureBasePtr _oth_ptr, T &&... all)
 Creates a factor of class classType and links it to the feature. More...
 
- Protected Member Functions inherited from wolf::FactorBase
void setProblem (ProblemPtr) override final
 Sets the problem and, if the factor is active, notifies the problem of its addition. More...
 
virtual void setProblem (ProblemPtr _prob_ptr)
 Sets the problem the node belongs to. More...
 

Detailed Description

template<class FacT, unsigned int RES, unsigned int... BLOCK_SIZES>
class wolf::FactorAutodiff< FacT, RES, BLOCK_SIZES >

Base class of factors with automatic differentiation: the Jacobians are computed with jets.

The derived class FacT computes RES residuals from the state blocks of sizes BLOCK_SIZES... by implementing:

  • template <typename T> bool residualAutodiff(const std::vector<const T*>& _states_ptr, Eigen::Matrix<T, RES, 1>& _residual) const;
  • template <typename T> Eigen::Matrix<T, ?, 1> expectationAutodiff(const std::vector<const T*>& _states_ptr) const;

where _states_ptr contains the pointers to the values of each state block (same order as in the constructor). Both are called with T = double and with T = WolfJet. The returned type of expectationAutodiff can be any Eigen vector.

Member Typedef Documentation

◆ WolfJet

template<class FacT , unsigned int RES, unsigned int... BLOCK_SIZES>
typedef autodiff::Jet<double, jet_size> wolf::FactorAutodiff< FacT, RES, BLOCK_SIZES >::WolfJet

Jet type, with the derivatives wrt all the state block components.

Constructor & Destructor Documentation

◆ FactorAutodiff()

template<class FacT , unsigned int RES, unsigned int... BLOCK_SIZES>
wolf::FactorAutodiff< FacT, RES, BLOCK_SIZES >::FactorAutodiff ( const std::string &  _type,
const FactorTopology &  _top,
const Eigen::VectorXd &  _measurement,
const Eigen::MatrixXd &  _measurement_sqrt_information_upper,
const NodeStateBlocksPtrList &  _node_state_block_list,
const ProcessorBasePtr &  _processor_ptr,
const std::vector< StateBlockPtr > &  _state_ptrs,
bool  _apply_loss_function,
FactorStatus  _status = FAC_ACTIVE 
)
inline

Constructor (see FactorBase). It checks the state block sizes and initializes the jets.

◆ ~FactorAutodiff()

template<class FacT , unsigned int RES, unsigned int... BLOCK_SIZES>
wolf::FactorAutodiff< FacT, RES, BLOCK_SIZES >::~FactorAutodiff ( )
overridedefault

Member Function Documentation

◆ evaluate()

template<class FacT , unsigned int RES, unsigned int... BLOCK_SIZES>
bool wolf::FactorAutodiff< FacT, RES, BLOCK_SIZES >::evaluate ( const std::vector< const double * > &  _states_ptr,
Eigen::VectorXd &  _residual,
std::vector< Eigen::MatrixXd > &  _jacobians 
) const
inlineoverridevirtual

Evaluates the residual and, if _jacobians is not empty, the Jacobians (see FactorBase::evaluate())

Implements wolf::FactorBase.

◆ expectation() [1/3]

template<class FacT , unsigned int RES, unsigned int... BLOCK_SIZES>
Eigen::VectorXd wolf::FactorBase::expectation ( ) const

Evaluates the expected measurement at the current state values.

◆ expectation() [2/3]

template<class FacT , unsigned int RES, unsigned int... BLOCK_SIZES>
Eigen::VectorXd wolf::FactorAutodiff< FacT, RES, BLOCK_SIZES >::expectation ( const std::vector< const double * > &  _states_ptr) const
inlineoverridevirtual

Evaluates the expected measurement at the state values in _states_ptr.

Implements wolf::FactorBase.

◆ expectation() [3/3]

template<class FacT , unsigned int RES, unsigned int... BLOCK_SIZES>
virtual Eigen::VectorXd wolf::FactorBase::expectation ( const std::vector< const double * > &  _states_ptr) const
virtual

Evaluates the expected measurement at the state values in _states_ptr.

Parameters
_states_ptrpointers to the values of each state block (same order as getStateBlockPtrVector())

Implements wolf::FactorBase.

◆ getSize()

template<class FacT , unsigned int RES, unsigned int... BLOCK_SIZES>
unsigned int wolf::FactorAutodiff< FacT, RES, BLOCK_SIZES >::getSize ( ) const
inlineoverridevirtual

Returns the residual size.

Implements wolf::FactorBase.

Member Data Documentation

◆ block_sizes_

template<class FacT , unsigned int RES, unsigned int... BLOCK_SIZES>
constexpr std::array<unsigned int, n_blocks> wolf::FactorAutodiff< FacT, RES, BLOCK_SIZES >::block_sizes_ {BLOCK_SIZES...}
staticconstexprprotected

Size of each state block.

◆ jacobian_locations_

template<class FacT , unsigned int RES, unsigned int... BLOCK_SIZES>
constexpr std::array<unsigned int, n_blocks> wolf::FactorAutodiff< FacT, RES, BLOCK_SIZES >::jacobian_locations_
staticconstexprprotected
Initial value:
=
detail::cumulativeOffsets<BLOCK_SIZES...>()
constexpr std::array< unsigned int, sizeof...(BLOCK_SIZES)> cumulativeOffsets()
Returns the position of each state block in a vector stacking all of them.
Definition: factor_autodiff.h:38

Position of each state block in the jets.

◆ jet_size

template<class FacT , unsigned int RES, unsigned int... BLOCK_SIZES>
constexpr unsigned int wolf::FactorAutodiff< FacT, RES, BLOCK_SIZES >::jet_size = (BLOCK_SIZES + ...)
staticconstexpr

Size of the derivatives part of the jets.

◆ n_blocks

template<class FacT , unsigned int RES, unsigned int... BLOCK_SIZES>
constexpr unsigned int wolf::FactorAutodiff< FacT, RES, BLOCK_SIZES >::n_blocks = sizeof...(BLOCK_SIZES)
staticconstexpr

Number of state blocks.

◆ residual_jets_

template<class FacT , unsigned int RES, unsigned int... BLOCK_SIZES>
Eigen::Matrix<WolfJet, RES, 1> wolf::FactorAutodiff< FacT, RES, BLOCK_SIZES >::residual_jets_
mutableprotected

Jets of the residual.

◆ state_jets_

template<class FacT , unsigned int RES, unsigned int... BLOCK_SIZES>
std::array<WolfJet, jet_size> wolf::FactorAutodiff< FacT, RES, BLOCK_SIZES >::state_jets_
mutableprotected

Jets of all state blocks (stacked)

◆ state_jets_ptr_

template<class FacT , unsigned int RES, unsigned int... BLOCK_SIZES>
std::vector<const WolfJet*> wolf::FactorAutodiff< FacT, RES, BLOCK_SIZES >::state_jets_ptr_
protected

Pointers to the jets of each state block.


The documentation for this class was generated from the following file: